package com.ywt.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.MenuItem;
import com.ywt.main.R;

public class PublishFragment extends SherlockFragment {

	View v;
	String[] applicationNames = new String[] { "玉米", "玉米", "玉米", "玉米", "玉米" };
	String[] applicationNames2 = new String[] { "吨", "公斤" };
	Spinner spinner1;
	Spinner spinner2;
	ArrayAdapter<String> aaAdapter1, aaAdapter2;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		v = inflater.inflate(R.layout.frag_publish, container, false);
		// registerForContextMenu(v.findViewById(R.id.show_context_menu));

		spinner1 = (Spinner) v.findViewById(R.id.spinner1);
		spinner2 = (Spinner) v.findViewById(R.id.spinner2);
		// 将上如下代码可以使列表项带RadioButton组件

		aaAdapter1 = new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_spinner_item, applicationNames);
		aaAdapter1
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		aaAdapter2 = new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_spinner_item, applicationNames2);
		aaAdapter2
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner1.setAdapter(aaAdapter1);
		spinner2.setAdapter(aaAdapter2);
		return v;
	}

	// @Override
	// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
	// MenuItem ads = menu.add("ads");
	// ads.setIcon(R.drawable.abs__ic_cab_done_holo_dark);
	// ads.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
	// ads.setOnMenuItemClickListener(new OnMenuItemClickListener() {
	// @Override
	// public boolean onMenuItemClick(MenuItem item) {
	// Toast.makeText(getActivity(), "发布···", Toast.LENGTH_LONG)
	// .show();
	// return true;
	// }
	// });

	// super.onCreateOptionsMenu(menu, inflater);
	// }

	// @Override
	// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
	// Used to put dark icons on light action bar
	// boolean isLight = SampleList.THEME == R.style.Theme_Sherlock_Light;

	// menu.add("Save")
	// .setIcon(isLight ? R.drawable.ic_compose_inverse : R.drawable.ic_compose)
	// .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
	//
	// menu.add("Search")
	// .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
	// MenuItem.SHOW_AS_ACTION_WITH_TEXT);
	//
	// menu.add("Refresh")
	// .setIcon(isLight ? R.drawable.ic_refresh_inverse : R.drawable.ic_refresh)
	// .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
	// MenuItem.SHOW_AS_ACTION_WITH_TEXT);

	// super.onCreateOptionsMenu(menu, inflater);
	// }

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		// Intent intent = new Intent(LoginActivity.this,
		// RegisterActivity.class);
		// LoginActivity.this.startActivityForResult(intent, 101);

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// This uses the imported MenuItem from ActionBarSherlock
		Toast.makeText(getActivity(), "Got click: " + item.toString(),
				Toast.LENGTH_SHORT).show();
		return true;
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenu.ContextMenuInfo menuInfo) {
		menu.add("One");
		menu.add("Two");
		menu.add("Three");
		menu.add("Four");
	}

	@Override
	public boolean onContextItemSelected(android.view.MenuItem item) {
		// Note how this callback is using the fully-qualified class name
		Toast.makeText(getActivity(), "Got click: " + item.toString(),
				Toast.LENGTH_SHORT).show();
		return true;
	}

}
